<template>
  <div class="c-chat" :class="{'c-chat-my__justify': record.userType === 'user'}">
    <!-- 个人 -->
    <template v-if="record.aiMessageType === 'FILE'">
      <div class="c-chat-my" :time="record.createTime" style="background-color: #FFFFFF; padding: 0">
        <div class="c-chat-file">
          <el-icon style="font-size: 25px; position: relative; bottom: 4px; margin-right: 5px;"><Document/></el-icon>
          <div style="display: inline-block; position:relative; line-height: 46px; bottom: 10px;">{{record.content}}</div>
        </div>
      </div>
    </template>
    <template v-else-if="record.userType === 'user'">
      <div class="c-chat-my" :time="record.createTime">
        <v-md-preview :text="record.content"></v-md-preview>
      </div>
    </template>
    <!-- ai -->
    <template v-else>
      <div class="c-chat-ai">
        <el-avatar src=""/>
        <div class="c-chat-ai__content">
          <v-md-preview :text="record.content"></v-md-preview>
        </div>
      </div>
    </template>
  </div>
</template>

<script setup>
import { getAiHistoryContent } from '@/request/ai.js'

const emits = defineEmits(['history'])

const props = defineProps({
  record: {
    type: Object,
    default: () => ({})
  },
})

const remove = () => {}
const replay = async () => {
  const { data } = await getAiHistoryContent({ aiSessionId: props.record.id })
  const history = data.filter(item => item.role === 'ASSISTANT')
  emits('history', { id: props.record.id, history })
}
</script>

<style lang="less">
.c-chat {
  display: flex;
  margin: 25px 0;
  word-wrap: break-word;
}
.c-chat-my__justify {
  justify-content: end;
  margin-top: 40px;
}
.c-chat-file {
  border: 1px solid rgba(0, 0, 0, .2);
  border-radius: 8px;
  height: 46px;
  padding: 10px;
  background-color: #ffffff;
}
.c-chat-my {
  max-width: calc(100% - 60px);
  display: inline-block;
  padding: 10px 15px;
  background-color: #f4f4f4;
  border-radius: 10px;
  position: relative;
  &:hover .c-chat-my__other {
    display: block;
  }
  &::before {
    content: attr(time);
    position: absolute;
    right: 5px;
    top: -22px;
    white-space: nowrap;
    font-size: 12px;
    color: rgb(180 187 196 / 2);
  }
}
.c-chat-ai {
  display: flex;
  width: 100%;
  border-radius: 20px;
}
.c-chat-ai__content {
  flex: 1;
  padding: 10px 20px;
  margin-left: 10px;
  word-break: break-word;
  box-sizing: border-box;
  p {
    margin-bottom: 20px;
  }
  max-width: calc(100% - 40px);
}
.c-chat-my__operator {
  display: flex;
  flex-direction: column;
  cursor: pointer;
  span:hover {
    color: #fff;
  }
}
.c-chat-my__other {
  display: none;
  position: absolute;
  transform: rotate(90deg) translateY(-50%);
  transform-origin: center center;
  left: -20px;
  cursor: pointer;
}
pre {
  border-radius: .375rem;
  padding: 10px;
  font-weight: 400;
  background-color: rgba(#0d0d0d, 0.9);
  code {
    word-wrap: normal;
    background: none;
    color: #fff;
    -webkit-hyphens: none;
    hyphens: none;
    line-height: 1.5;
    tab-size: 4;
    white-space: pre;
    word-break: normal;
    word-spacing: normal;
  }
}
</style>